<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;

class ChangeTempCate extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'command:tempCate';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     */
    public function handle()
    {
        $lists = DB::table('personal_page_template_user')->get();
        $lists->each(function ($item){
            $cate = DB::table('personal_page_template')->where('id',$item->template_id)->first(['cate']);
            if ($cate) {
                DB::table('personal_page_template_user')->where('id', $item->id)->update(['cate' => $cate->cate]);
            }
        });
    }
}
